#include<bits/stdc++.h>
using namespace std;

int T,n,ans;
int a[200009];
int c[200009];
void dfs(int dep,int num)
{
    if(dep==n)
    {
        ans=max(ans,num);
        return;
    }
    int gong=0;
    c[dep]=1;
    for(int i=dep-1;i>=0;i--)
    {
        if(c[i]==c[dep])
        {
            if(a[i]==a[dep])gong=a[i];
            break;
        }
    }
    dfs(dep+1,num+gong);

    gong=0;
    c[dep]=2;
    for(int i=dep-1;i>=0;i--)
    {
        if(c[i]==c[dep])
        {
            if(a[i]==a[dep])gong=a[i];
            break;
        }
    }
    dfs(dep+1,num+gong);
    return;
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin>>T;
    while(T--)
    {
        ans=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        dfs(0,0);
        cout<<ans<<endl;
    }

    return 0;
}
